package dao;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnection {
	
	public static Connection getConnection(String url,String user,String password,String dbType){
		if(dbType.equals("oracle")){
			return oracleConnection(url, user, password);
		}else if(dbType.equals("mysql")){
			return mariadbConnection(url, user, password);
		}else{
			return null;
		}
	}
	
	public static Connection oracleConnection(String url,String user,String password){
		Connection conn=null;
		try{
			Class.forName("oracle.jdbc.OracleDriver");
			url="jdbc:oracle:thin:@"+url;
			conn=DriverManager.getConnection(url, user, password);
		}catch(Exception ex){
			ex.printStackTrace();
			 return null;
		}
		return conn;
	}
	
	public static Connection mariadbConnection(String url,String user,String password){
		Connection conn=null;
		try{
			Class.forName("org.mariadb.jdbc.Driver");
			url="jdbc:mysql://"+url;
			conn=DriverManager.getConnection(url, user, password);
		}catch(Exception ex){
			ex.printStackTrace();
			 return null;
		}
		return conn;
	}
	
	
}
